#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <svc.h> //albert change from " " to < > 08032004
#include <ucldefine.h>
#include "appobj.h"
#include "applidl.h"
#include <define.h>
#include <actutil.h>
#include "uclids.h"

// For Landline
static char baudRate = Rt_9600;
static char format = Fmt_A8N1|Fmt_DTR|Fmt_RTS;
static char protocol = P_char_mode;
static char mdmType = SINGLE_PORT;
static char dialType = TONE ; //BLIDN;
static long escapeGuardTime = 1300;
static char sdlcparmoption = P_sdlc_sec;
static char sdlcparmaddress = 0x30;
static char parameter = 0x00;
static unsigned char phoneNo[MAX_PHNO_LENGTH] = "*99***1#";
#ifdef _TARG_68000
static unsigned char initString[MAX_INIT_STR_LEN] = "AT&D2Q0S0=1" ;/*"ATB0&K0%C0\N3&D2+MS=V32S7=60";*/
#elif __arm
static unsigned char initString[MAX_INIT_STR_LEN] = "ATE0V0&D2&Q0X4&Z0%E1" ;///*"ATB0&K0%C0\N3&D2+MS=V32S7=60";*/"AT&D2Q0S0=1" ;
#endif
static unsigned char hangUpString[MAX_HANGUP_STR_LEN] = "ATH0";
static unsigned char startUpString[MAX_STARTUP_STR_LEN] =  "ATE0V0";
static unsigned char modelNo[MAX_MODEL_SIZE] =  "CONEXANT";


// For GSM
static char baudRateGsm = Rt_115200; // for GSM always 
static char formatGsm = Fmt_A8N1|Fmt_DTR|Fmt_RTS; // for GSM it must be always Fmt_A8N1
static char protocolGsm = P_char_mode;
static long escapeGuardTimeGsm = 1500;
static char sdlcparmoptionGsm = P_sdlc_sec;
static char sdlcparmaddressGsm = 0x30;
static char parameterGsm = 0x00;
static unsigned char hangUpStringGsm[MAX_HANGUP_STR_LEN] = "ATH";
static unsigned char initStringGsm[MAX_INIT_STR_LEN] = "AT+CBST=7,0,1";
static unsigned char startUpStringGsm[MAX_STARTUP_STR_LEN] =  "ATE0V0&D2S0=1";//"ATB0&K0%C0\N3&D2+MS=V32S7=60";
static unsigned char phoneNoGsm[MAX_PHNO_LENGTH] = "9845429492";//"9845429492";9886107536
static unsigned char modelNoGsm[MAX_MODEL_SIZE] =  "O3600P"; // 
static short minBatteryStrength = 25;
static short minSignalStrength = 4;
static short lcWaitTimeGsm = 6000;
static short nwWaitTimeGsm = 5000;


// For GPRS
static char baudRateGprs = Rt_115200; // for GSM always Rt_9600
static char formatGprs = Fmt_A8N1|Fmt_DTR|Fmt_RTS; // for Gprs it must be always Fmt_A8N1
static char protocolGprs = P_char_mode;
static long escapeGuardTimeGprs = 1500;
static char sdlcparmoptionGprs = P_sdlc_sec;
static char sdlcparmaddressGprs = 0x30;
static char parameterGprs = 0x00;
static unsigned char hangUpStringGprs[MAX_HANGUP_STR_LEN] = "ATH";
static unsigned char initStringGprs[MAX_INIT_STR_LEN] = "ATQ0&D1";
static unsigned char startUpStringGprs[MAX_STARTUP_STR_LEN] =  "ATE0V0";//"ATB0&K0%C0\N3&D2+MS=V32S7=60";
static unsigned char phoneNoGprs[MAX_PHNO_LENGTH] = "*99***1#";//"9845429492";
static unsigned char modelNoGprs[MAX_MODEL_SIZE] =  "GPRS_SIEMENS"; // always 3600G
static short minBatteryStrengthGprs = 25;
static short minSignalStrengthGprs = 4;
static short lcWaitTimeGprs = 100;
#ifdef _TARG_68000
	static short nwWaitTimeGprs = 100;
#elif __arm
	static short nwWaitTimeGprs = 5000;
#endif

static unsigned char packetProtocol[MAX_PACKET_PROTOCOL_SIZE] = "IP";
static unsigned char apn[MAX_APN_LENGTH] = "proxy";
#ifdef _TARG_68000
static unsigned char terminalTypeGprs[MAX_TERM_TYPE_SIZE] = "O37xx";
#elif __arm
static unsigned char terminalTypeGprs[MAX_TERM_TYPE_SIZE] = "O56xx";
#endif


// For CDMA
static char baudRateCdma = Rt_115200; // for GSM always Rt_9600
static char formatCdma = Fmt_A8N1|Fmt_DTR|Fmt_RTS; // for Cdma it must be always Fmt_A8N1
static char protocolCdma = P_char_mode;
static long escapeGuardTimeCdma = 1500;
static char sdlcparmoptionCdma = P_sdlc_sec;
static char sdlcparmaddressCdma = 0x30;
static char parameterCdma = 0x00;
static unsigned char hangUpStringCdma[MAX_HANGUP_STR_LEN] = "ATH";
static unsigned char initStringCdma[MAX_INIT_STR_LEN] = "ATQ0";
static unsigned char startUpStringCdma[MAX_STARTUP_STR_LEN] =  "ATE0V0";//"ATB0&K0%C0\N3&D2+MS=V32S7=60";
static unsigned char phoneNoCdma[MAX_PHNO_LENGTH] = "#777";//"9845429492";
static unsigned char modelNoCdma[MAX_MODEL_SIZE] =  "CDMA_SIERRA"; // always 3600G
static short minBatteryStrengthCdma = 25;
static short minSignalStrengthCdma = 4;
#ifdef _TARG_68000
	static short lcWaitTimeCdma = 500;
#elif __arm
	static short lcWaitTimeCdma = 4500;
#endif

static short nwWaitTimeCdma = 500;
#ifdef _TARG_68000
static unsigned char terminalTypeCdma[MAX_TERM_TYPE_SIZE] = "O37xx";
#elif __arm
static unsigned char terminalTypeCdma[MAX_TERM_TYPE_SIZE] = "O56xx";
#endif


// For CO
static char baudRateCO = Rt_9600; // for GSM always Rt_9600
static char formatCO = Fmt_A8N1|Fmt_DTR|Fmt_RTS; // for CO it must be always Fmt_A8N1
static char protocolCO = P_char_mode;
static char parameterCO = 0x00;
static unsigned char hangUpStringCO[MAX_HANGUP_STR_LEN] = "ATH";
static unsigned char initStringCO[MAX_INIT_STR_LEN] = "AT+iE0";
static unsigned char startUpStringCO[MAX_STARTUP_STR_LEN] =  "AT+i";//"ATB0&K0%C0\N3&D2+MS=V32S7=60";
static unsigned char modelNoCO[MAX_MODEL_SIZE] =  "ETHERNET_ICHIP"; 

// For WiFi
static char baudRateWiFi = Rt_115200; // for GSM always Rt_9600
static char formatWiFi = Fmt_A8N1|Fmt_DTR|Fmt_RTS; // for CO it must be always Fmt_A8N1
static char protocolWiFi = P_char_mode;
static char parameterWiFi = 0x00;
static unsigned char hangUpStringWiFi[MAX_HANGUP_STR_LEN] = "ATH";
static unsigned char initStringWiFi[MAX_INIT_STR_LEN] = "AT+iE0";
static unsigned char startUpStringWiFi[MAX_STARTUP_STR_LEN] =  "AT+i";//"ATB0&K0%C0\N3&D2+MS=V32S7=60";
static unsigned char modelNoWiFi[MAX_MODEL_SIZE] =  "WIFI_ICHIP"; 
#ifdef _TARG_68000
static unsigned char terminalTypeWiFi[MAX_TERM_TYPE_SIZE] = "O37xx";
#elif __arm
static unsigned char terminalTypeWiFi[MAX_TERM_TYPE_SIZE] = "O56xx";
#endif

extern int Nprintf(char *format,...); 

/*rajkiran 26/3/04*/
int conHandle;
int retVal=0;

/****************************************************************************
* FUNCTION NAME		: GetParamLandLine()

* INPUTS			: paramId - ID of the parameter required
					  value    - buffer to hold parameter value 
					  size     - size of the value. 

* OUTPUTS			: required ID value is updated and no. of bytes/errNo is returned 

* DESCRIPTION		: This method is called by library APIs to get the user specified values
                      of the communication parameters.  
 
****************************************************************************/


short GetParamLandLine(short paramId, unsigned char *buffer, short size)
{
	if((buffer == NULL) ||(size <= 0))
		return E_UCL_INVALID_PARM;
	
	memset(buffer,0,size);
	
	switch (paramId)
	{
	case ESCAPE_GUARD_TIME:
			sprintf((char*)buffer, "%ld",escapeGuardTime);
			return strlen((char*)buffer);
	case BAUDRATE:
			buffer[0] = baudRate;
			buffer[1] = '\0';
			return SINGLE_CHAR_SIZE;
	case FORMAT:
			buffer[0] = format;
			buffer[1] = '\0';
			return SINGLE_CHAR_SIZE;
	case PARAMETER:
			buffer[0] = parameter;
			buffer[1] = '\0';
			return SINGLE_CHAR_SIZE;
	case PROTOCOL:
			buffer[0] = protocol;
			buffer[1] = '\0';
			return SINGLE_CHAR_SIZE;
	case SDLC_PARM_OPTION:
			buffer[0] = sdlcparmoption;
			buffer[1] = '\0';
			return SINGLE_CHAR_SIZE;
	case SDLC_PARM_ADDRESS:
			buffer[0] = sdlcparmaddress;
			buffer[1] = '\0';
			return SINGLE_CHAR_SIZE;
	case MDM_TYPE:
			buffer[0] = mdmType;
			buffer[1] = '\0';
			return SINGLE_CHAR_SIZE;
	case DIAL_TYPE:
			buffer[0] = dialType;
			buffer[1] = '\0';
			return SINGLE_CHAR_SIZE;
	case PHONE_NUMBER:
			if(get_env("#PHONE",(char*)phoneNo,MAX_PHNO_LENGTH) > 0)
				strcpy((char*)buffer,(char*)phoneNo);
			else
				strcpy((char*)buffer,(char*)phoneNo);
			return strlen((char*)phoneNo);
	case INIT_STRING:
			memcpy(buffer, initString,MAX_INIT_STR_LEN);
			return MAX_INIT_STR_LEN;
	case HANGUP_STRING:
			memcpy(buffer, hangUpString,MAX_HANGUP_STR_LEN);
			return MAX_HANGUP_STR_LEN;
	case STARTUP_STRING:
			memcpy(buffer, startUpString,MAX_STARTUP_STR_LEN);
			return MAX_STARTUP_STR_LEN;
	case MODEL_NO:
			memcpy(buffer, modelNo,MAX_MODEL_SIZE);
			return MAX_MODEL_SIZE;
	default:
		break;
	}
	return UCL_FAILURE;
};


/****************************************************************************
* FUNCTION NAME		: SetParamLandLine()

* INPUTS			: paramId - ID of the parameter required
					  value    - buffer with parameter value 
					  size     - size of the value. 
  					 

* OUTPUTS			: returns if the internal data has been updated or not 
						SUCCESS /FAILURE

* DESCRIPTION		: This method is used by the application to update the 
						communication parameters.

****************************************************************************/

short SetParamLandLine(short paramId, unsigned char *buffer, short size)
{
	if(buffer == NULL)
		return UCL_FAILURE;
	if(size == 0)
		return UCL_FAILURE;
	switch (paramId)
	{
	case ESCAPE_GUARD_TIME:
			escapeGuardTime = atoi((char*)buffer);
			break;
	
	case BAUDRATE:
			baudRate = buffer[0];
			break;
	case FORMAT:
			format = buffer[0];
			break;

	case PROTOCOL:
			protocol = buffer[0];
			break;
	case PARAMETER:
			parameter = buffer[0];
			break;
	case SDLC_PARM_OPTION:
		sdlcparmoption = buffer[0];
		break;
	case SDLC_PARM_ADDRESS: 
		sdlcparmaddress = buffer[0];
		break;
	
	case MDM_TYPE:
			mdmType = buffer[0];
			break;
	case DIAL_TYPE:
			dialType = buffer[0];
			break;
	case PHONE_NUMBER:
			memset(phoneNo, '\0', MAX_PHNO_LENGTH);
			memcpy(phoneNo, buffer,size);
			return size;
	case INIT_STRING:
			memset(initString, '\0', MAX_INIT_STR_LEN);
			memcpy(initString, buffer,size);
			return size;
	case HANGUP_STRING:
			memset(hangUpString, '\0', MAX_HANGUP_STR_LEN);
			memcpy(hangUpString, buffer,size);
			return size;
	case STARTUP_STRING:
			memset(startUpString, '\0', MAX_STARTUP_STR_LEN);
			memcpy(startUpString, buffer,size);
			return size;
	case MODEL_NO:
			memset(modelNo, '\0', MAX_MODEL_SIZE);
			memcpy(modelNo, buffer,size);
			return size;
	default:

		return UCL_FAILURE;
	}
	return UCL_SUCCESS;
};



/****************************************************************************
* FUNCTION NAME		: GetParamGSM()

* INPUTS			: paramId - ID of the parameter required
					  value    - buffer to hold parameter value 
					  size     - size of the value. 

* OUTPUTS			: required ID value is updated and no. of bytes/errNo is returned 

* DESCRIPTION		: This method is called by library APIs to get the user specified values
                      of the communication parameters.  
 
****************************************************************************/


short GetParamGsm(short paramId, unsigned char *buffer, short size)
{
	if((buffer == NULL) ||(size <= 0))
		return E_UCL_INVALID_PARM;
	
	memset(buffer,0,size);
	
	switch (paramId)
	{
	case ESCAPE_GUARD_TIME:
			sprintf((char*)buffer, "%ld",escapeGuardTimeGsm);
			return strlen((char*)buffer);

	case BAUDRATE:
			buffer[0] = baudRateGsm;
			buffer[1] = '\0';
			return SINGLE_CHAR_SIZE;
	
	case FORMAT:
			buffer[0] = formatGsm;
			buffer[1] = '\0';
			return SINGLE_CHAR_SIZE;
	case PARAMETER:
			buffer[0] = parameterGsm;
			buffer[1] = '\0';
			return SINGLE_CHAR_SIZE;
	case PROTOCOL:
			buffer[0] = protocolGsm;
			buffer[1] = '\0';
			return SINGLE_CHAR_SIZE;
	case SDLC_PARM_OPTION:
			buffer[0] = sdlcparmoptionGsm;
			buffer[1] = '\0';
			return SINGLE_CHAR_SIZE;
	case SDLC_PARM_ADDRESS:
			buffer[0] = sdlcparmaddressGsm;
			buffer[1] = '\0';
			return SINGLE_CHAR_SIZE;
	case PHONE_NUMBER:
			get_env("#PHONE",(char*)buffer,30);
			return MAX_PHNO_LENGTH;
	case INIT_STRING:
			memcpy(buffer, initStringGsm,MAX_INIT_STR_LEN);
			return MAX_INIT_STR_LEN;
	case HANGUP_STRING:
			memcpy(buffer, hangUpStringGsm,MAX_HANGUP_STR_LEN);
			return MAX_HANGUP_STR_LEN;
	case STARTUP_STRING:
			memcpy(buffer, startUpStringGsm,MAX_STARTUP_STR_LEN);
			return MAX_STARTUP_STR_LEN;
	case MODEL_NO:
			memcpy(buffer, modelNoGsm,MAX_MODEL_SIZE);
			return MAX_MODEL_SIZE;
	case MIN_BATTERY_STRENGTH:
			sprintf((char*)buffer, "%d",minBatteryStrength);
			return strlen((char*)buffer);
	case MIN_SIGNAL_STRENGTH:
			sprintf((char*)buffer, "%d",minSignalStrength);
			return strlen((char*)buffer);
	case LOCAL_CMD_WAIT_TIME:
			sprintf((char*)buffer, "%d",lcWaitTimeGsm);
			return strlen((char*)buffer);
	case NW_CMD_WAIT_TIME:
			sprintf((char*)buffer, "%d",nwWaitTimeGsm);
			return strlen((char*)buffer);
	default:
		break;
	}
	return UCL_FAILURE;
};


/****************************************************************************
* FUNCTION NAME		: SetParamGsm()

* INPUTS			: paramId - ID of the parameter required
					  value    - buffer with parameter value 
					  size     - size of the value. 
  					 

* OUTPUTS			: returns if the internal data has been updated or not 
						SUCCESS /FAILURE

* DESCRIPTION		: This method is used by the application to update the 
						communication parameters.

****************************************************************************/

short SetParamGsm(short paramId, unsigned char *buffer, short size)
{
	if(buffer == NULL)
		return UCL_FAILURE;
	if(size == 0)
		return UCL_FAILURE;
	switch (paramId)
	{
	case ESCAPE_GUARD_TIME:
			escapeGuardTimeGsm = atoi((char*)buffer);
			break;
	case BAUDRATE:
			baudRateGsm = buffer[0];
			break;
	case FORMAT:
			formatGsm = buffer[0];
			break;

	case PROTOCOL:
			protocolGsm = buffer[0];
			break;
	case PARAMETER:
			parameterGsm = buffer[0];
			break;
	case SDLC_PARM_OPTION:
		sdlcparmoptionGsm = buffer[0];
		break;
	case SDLC_PARM_ADDRESS: 
		sdlcparmaddressGsm = buffer[0];
		break;

	case PHONE_NUMBER:
			memset(phoneNoGsm, '\0', MAX_PHNO_LENGTH);
			memcpy(phoneNoGsm, buffer,size);
			return size;
	case INIT_STRING:
			memset(initStringGsm, '\0', MAX_INIT_STR_LEN);
			memcpy(initStringGsm, buffer,size);
			return size;
	case HANGUP_STRING:
			memset(hangUpStringGsm, '\0', MAX_HANGUP_STR_LEN);
			memcpy(hangUpStringGsm, buffer,size);
			return size;
	case STARTUP_STRING:
			memset(startUpStringGsm, '\0', MAX_STARTUP_STR_LEN);
			memcpy(startUpStringGsm, buffer,size);
			return size;
	case MODEL_NO:
			memset(modelNoGsm, '\0', MAX_MODEL_SIZE);
			memcpy(modelNoGsm, buffer,size);
			return size;
	case MIN_BATTERY_STRENGTH:
			minBatteryStrength = atoi((char*)buffer);		
			break;
	case MIN_SIGNAL_STRENGTH:
			minSignalStrength = atoi((char*)buffer);		
			break;
	case LOCAL_CMD_WAIT_TIME:
			lcWaitTimeGsm = atoi((char*)buffer);
			break;
	case NW_CMD_WAIT_TIME:
			nwWaitTimeGsm = atoi((char*)buffer);
			break;
	default:

		return UCL_FAILURE;
	}
	return UCL_SUCCESS;
};


/****************************************************************************
* FUNCTION NAME		: NotifyLandLine()

* INPUTS			: state    - ID of the parameter required
					 

* OUTPUTS			: return the terminal status

* DESCRIPTION		: This method is called by library APIs to inform the user about device status
                      and waits for the user response.  

****************************************************************************/
#if 0
short NotifyLandLine(short state)
{
	if(state == STATUS_DOCKED)
	{
		state = 0;
		write_at("handheld docked", 15, 1, 8);
	}
	else if(state == STATUS_UNDOCKED)
	{
		write_at("\fPlease dock handheld", 21, 1,1);
		state = 0;
	}
	return state;
}
#endif

short NotifyLandLine(short state)
{
	int retVal=0;
	if(state == STATUS_DOCKED)
	{
		state = 0;
		write_at("handheld docked", 15, 1, 8);
	}
	else if(state == STATUS_UNDOCKED)
	{
		write_at("\fPlease dock handheld", 21, 1,1);
		state = 0;
	}
	else if(state == STATUS_RECV)
	{
		char buff[10]={0};
		retVal = act_kbd_pending_test(KEY_CANCEL);
		if(retVal == 1){
			state = -1;
			read(conHandle,buff,5);
		}
		else
			state = 0;
		
	}
	return state;
}


/****************************************************************************
* FUNCTION NAME		: NotifyGsm()

* INPUTS			: state    - ID of the parameter required
					 

* OUTPUTS			: return the terminal status

* DESCRIPTION		: This method is called by library APIs to inform the user about device status
                      and waits for the user response.  

****************************************************************************/

short NotifyGsm(short state)
{
	if(state == STATUS_RECV)
	{
		char buff[10]={0};
		retVal = act_kbd_pending_test(KEY_CANCEL);
		if(retVal == 1)
		{
			state = -1;
			read(conHandle,buff,5);
		}
		else
			state = 0;
		
	}
	return state;
}


/****************************************************************************
* FUNCTION NAME		: GetParamGprs()

* INPUTS			: paramId - ID of the parameter required
					  value    - buffer to hold parameter value 
					  size     - size of the value. 

* OUTPUTS			: required ID value is updated and no. of bytes/errNo is returned 

* DESCRIPTION		: This method is called by library APIs to get the user specified values
                      of the communication parameters.  
 
****************************************************************************/

short GetParamGprs(short paramId, unsigned char *buffer, short size)
{

	int inProfile=get_env_int("*PROFILE"); //LeeChyi - 16092005: Added in
	
	unsigned char temp[36+1];
	
	if((buffer == NULL) ||(size <= 0))
		return E_UCL_INVALID_PARM;
	
	//LeeChyi - 16092005: Modified
	//if(inLoadGPTRec(0) != 0)
	if(inLoadGPTRec(inProfile-1) != 0)
	 	return UCL_FAILURE;
	
	memset(buffer,0,size);
	
	switch (paramId)
	{
	case ESCAPE_GUARD_TIME:
			sprintf((char*)buffer, "%ld",escapeGuardTimeGprs);
			return strlen((char*)buffer);

	case NWCHECK:
			buffer[0] = 0;
			buffer[1] = '\0';
			return SINGLE_CHAR_SIZE;
	case BAUDRATE:
			buffer[0] = baudRateGprs;
			buffer[1] = '\0';
			Nprintf((char*)buffer);
			return SINGLE_CHAR_SIZE;
	
	case FORMAT:
			buffer[0] = formatGprs;
			buffer[1] = '\0';
			Nprintf((char*)buffer);
			return SINGLE_CHAR_SIZE;
	case PARAMETER:
			buffer[0] = parameterGprs;
			buffer[1] = '\0';
			Nprintf((char*)buffer);
			return SINGLE_CHAR_SIZE;
	case PROTOCOL:
			buffer[0] = protocolGprs;
			buffer[1] = '\0';
			Nprintf((char*)buffer);
			return SINGLE_CHAR_SIZE;
	case SDLC_PARM_OPTION:
			buffer[0] = sdlcparmoptionGprs;
			buffer[1] = '\0';
			return SINGLE_CHAR_SIZE;
	case SDLC_PARM_ADDRESS:
			buffer[0] = sdlcparmaddressGprs;
			buffer[1] = '\0';
			return SINGLE_CHAR_SIZE;
	case PHONE_NUMBER:
 			strcpy((char*)buffer,(char*)szGetPhoneNoGprs());
			return strlen((char*)szGetPhoneNoGprs());
	case INIT_STRING:
			memcpy(buffer, initStringGprs,MAX_INIT_STR_LEN);
			return MAX_INIT_STR_LEN;
	case HANGUP_STRING:
			memcpy(buffer, hangUpStringGprs,MAX_HANGUP_STR_LEN);
			return MAX_HANGUP_STR_LEN;
	case STARTUP_STRING:
			memcpy(buffer, startUpStringGprs,MAX_STARTUP_STR_LEN);
			return MAX_STARTUP_STR_LEN;
	case MODEL_NO:
			memcpy(buffer, modelNoGprs,MAX_MODEL_SIZE);
			Nprintf((char*)buffer);
			return MAX_MODEL_SIZE;
	case MIN_BATTERY_STRENGTH:
			sprintf((char*)buffer, "%d",minBatteryStrengthGprs);
			return strlen((char*)buffer);
	case MIN_SIGNAL_STRENGTH:
			sprintf((char*)buffer, "%d",minSignalStrengthGprs);
			return strlen((char*)buffer);
	case LOCAL_CMD_WAIT_TIME:
			sprintf((char*)buffer, "%d",lcWaitTimeGprs);
			return strlen((char*)buffer);
	case NW_CMD_WAIT_TIME:
			sprintf((char*)buffer, "%d",nwWaitTimeGprs);
			return strlen((char*)buffer);
	case APN:
			memset(temp,0,sizeof(temp));
			strcpy((char*)temp,(char*)szGetAPN());
			memcpy(buffer,temp,MAX_APN_LENGTH);
			return MAX_APN_LENGTH;
			//break;
	case PACKET_PROTOCOL:
			strncpy((char*)buffer,(char*)packetProtocol,MAX_PACKET_PROTOCOL_SIZE-1);
			return MAX_PACKET_PROTOCOL_SIZE;
			//break;
	case TERMINAL_TYPE :
			strcpy((char*)buffer,(char*)terminalTypeGprs);
			return (strlen((char*)buffer));
	default:
		break;
	}
	return UCL_FAILURE;
};


/****************************************************************************
* FUNCTION NAME		: SetParamGprs()

* INPUTS			: paramId - ID of the parameter required
					  value    - buffer with parameter value 
					  size     - size of the value. 
  					 

* OUTPUTS			: returns if the internal data has been updated or not 
						SUCCESS /FAILURE

* DESCRIPTION		: This method is used by the application to update the 
						communication parameters.

****************************************************************************/

short SetParamGprs(short paramId, unsigned char *buffer, short size)
{
       Nprintf("set param");
	if(buffer == NULL)
		return UCL_FAILURE;
	if(size == 0)
		return UCL_FAILURE;
	switch (paramId)
	{
	case ESCAPE_GUARD_TIME:
			escapeGuardTimeGprs = atoi((char*)buffer);
			break;
	case BAUDRATE:
			baudRateGprs = buffer[0];
			break;
	case FORMAT:
			formatGprs = buffer[0];
			break;

	case PROTOCOL:
			protocolGprs = buffer[0];
			break;
	case PARAMETER:
			parameterGprs = buffer[0];
			break;
	case SDLC_PARM_OPTION:
		sdlcparmoptionGprs = buffer[0];
		break;
	case SDLC_PARM_ADDRESS: 
		sdlcparmaddressGprs = buffer[0];
		break;
	

	case PHONE_NUMBER:
			memset(phoneNoGprs, '\0', MAX_PHNO_LENGTH);
			memcpy(phoneNoGprs, buffer,size);
			return size;
	case INIT_STRING:
			memset(initStringGprs, '\0', MAX_INIT_STR_LEN);
			memcpy(initStringGprs, buffer,size);
			return size;
	case HANGUP_STRING:
			memset(hangUpStringGprs, '\0', MAX_HANGUP_STR_LEN);
			memcpy(hangUpStringGprs, buffer,size);
			return size;
	case STARTUP_STRING:
			memset(startUpStringGprs, '\0', MAX_STARTUP_STR_LEN);
			memcpy(startUpStringGprs, buffer,size);
			return size;
	case MODEL_NO:
			memset(modelNoGprs, '\0', MAX_MODEL_SIZE);
			memcpy(modelNoGprs, buffer,size);
			Nprintf((char*)buffer);
			return size;
	case MIN_BATTERY_STRENGTH:
			minBatteryStrengthGprs = atoi((char*)buffer);		
			break;
	case MIN_SIGNAL_STRENGTH:
			minSignalStrengthGprs = atoi((char*)buffer);		
			break;
	case LOCAL_CMD_WAIT_TIME:
			lcWaitTimeGprs = atoi((char*)buffer);
			break;
	case NW_CMD_WAIT_TIME:
			nwWaitTimeGprs = atoi((char*)buffer);
			break;
	case APN:
			memset(apn, '\0', MAX_APN_LENGTH);
			memcpy(apn, buffer,size);
			return size;
	case PACKET_PROTOCOL:
			memset(packetProtocol, '\0',MAX_PACKET_PROTOCOL_SIZE);
			memcpy(packetProtocol, buffer,size);
			return size;

	default:

		return UCL_FAILURE;
	}
	return UCL_SUCCESS;
};
/****************************************************************************
* FUNCTION NAME		: NotifyGprs()

* INPUTS			: state    - ID of the parameter required
					 

* OUTPUTS			: return the terminal status

* DESCRIPTION		: This method is called by library APIs to inform the user about device status
                      and waits for the user response.  

****************************************************************************/

short NotifyGprs(short state)
{
	char buff[10]={0};	
	switch(state)
	{

	case STATUS_INITRADIO:
		{	
			SVC_WAIT(1);
			// Do the Softpay intialization here
			Nprintf("Intialising the radio");
		}
		return UCL_SUCCESS;
		//break;

	case STATUS_DIAL:
		Nprintf("Connecting to NW.....");
		return UCL_SUCCESS;	
		//break;

	case STATUS_REG:
		Nprintf("Resigestering to NW.....");
		return UCL_SUCCESS;	
		//break;

	case STATUS_ATTACH:
		Nprintf("Attaching to GPRS .....");
		return UCL_SUCCESS;	
		//break;

	case STATUS_RECV:
		retVal = act_kbd_pending_test(KEY_CANCEL);
		if(retVal == 1){
			state = -1;
			read(conHandle,buff,5);
		}
		else
			state = 0;
		break;
		
	default:
		Nprintf("Default Wait Not Handled..");
		return UCL_SUCCESS;
	}

	return state;
}


/****************************************************************************
* FUNCTION NAME		: GetParamGprs()

* INPUTS			: paramId - ID of the parameter required
					  value    - buffer to hold parameter value 
					  size     - size of the value. 

* OUTPUTS			: required ID value is updated and no. of bytes/errNo is returned 

* DESCRIPTION		: This method is called by library APIs to get the user specified values
                      of the communication parameters.  
 
****************************************************************************/

short GetParamCdma(short paramId, unsigned char *buffer, short size)
{
	if((buffer == NULL) ||(size <= 0))
		return E_UCL_INVALID_PARM;
	
	memset(buffer,0,size);
	
	switch (paramId)
	{
	case ESCAPE_GUARD_TIME:
			sprintf((char*)buffer, "%ld",escapeGuardTimeCdma);
			return strlen((char*)buffer);

	case BAUDRATE:
			buffer[0] = baudRateCdma;
			buffer[1] = '\0';
			return SINGLE_CHAR_SIZE;
	
	case FORMAT:
			buffer[0] = formatCdma;
			buffer[1] = '\0';
			return SINGLE_CHAR_SIZE;
	case PARAMETER:
			buffer[0] = parameterCdma;
			buffer[1] = '\0';
			return SINGLE_CHAR_SIZE;
	case PROTOCOL:
			buffer[0] = protocolCdma;
			buffer[1] = '\0';
			return SINGLE_CHAR_SIZE;
	case SDLC_PARM_OPTION:
			buffer[0] = sdlcparmoptionCdma;
			buffer[1] = '\0';
			return SINGLE_CHAR_SIZE;
	case SDLC_PARM_ADDRESS:
			buffer[0] = sdlcparmaddressCdma;
			buffer[1] = '\0';
			return SINGLE_CHAR_SIZE;
	case PHONE_NUMBER:
			if(get_env("#PHONE",(char*)phoneNo,MAX_PHNO_LENGTH) > 0)
			{
				strcpy((char*)buffer,(char*)phoneNo);
				return MAX_PHNO_LENGTH;
			}
			else
				strcpy((char*)buffer,(char*)phoneNoCdma);
			return MAX_PHNO_LENGTH;

	case INIT_STRING:
			memcpy(buffer, initStringCdma,MAX_INIT_STR_LEN);
			return MAX_INIT_STR_LEN;
	case HANGUP_STRING:
			memcpy(buffer, hangUpStringCdma,MAX_HANGUP_STR_LEN);
			return MAX_HANGUP_STR_LEN;
	case STARTUP_STRING:
			memcpy(buffer, startUpStringCdma,MAX_STARTUP_STR_LEN);
			return MAX_STARTUP_STR_LEN;
	case MODEL_NO:
			memcpy(buffer, modelNoCdma,MAX_MODEL_SIZE);
			return MAX_MODEL_SIZE;
	case MIN_BATTERY_STRENGTH:
			sprintf((char*)buffer, "%d",minBatteryStrength);
			return strlen((char*)buffer);
	case MIN_SIGNAL_STRENGTH:
			sprintf((char*)buffer, "%d",minSignalStrength);
			return strlen((char*)buffer);
	case LOCAL_CMD_WAIT_TIME:
			sprintf((char*)buffer, "%d",lcWaitTimeCdma);
			return strlen((char*)buffer);
	case NW_CMD_WAIT_TIME:
			sprintf((char*)buffer, "%d",nwWaitTimeCdma);
			return strlen((char*)buffer);
	case TERMINAL_TYPE :
			strcpy((char*)buffer,(char*)terminalTypeCdma);
			return (strlen((char*)buffer));
	default:
		break;
	}
	return UCL_FAILURE;
};


/****************************************************************************
* FUNCTION NAME		: SetParamCdma()

* INPUTS			: paramId - ID of the parameter required
					  value    - buffer with parameter value 
					  size     - size of the value. 
  					 

* OUTPUTS			: returns if the internal data has been updated or not 
						SUCCESS /FAILURE

* DESCRIPTION		: This method is used by the application to update the 
						communication parameters.

****************************************************************************/

short SetParamCdma(short paramId, unsigned char *buffer, short size)
{
	if(buffer == NULL)
		return UCL_FAILURE;
	if(size == 0)
		return UCL_FAILURE;
	switch (paramId)
	{
	case ESCAPE_GUARD_TIME:
			escapeGuardTimeCdma = atoi((char*)buffer);
			break;
	case BAUDRATE:
			baudRateCdma = buffer[0];
			break;
	case FORMAT:
			formatCdma = buffer[0];
			break;

	case PROTOCOL:
			protocolCdma = buffer[0];
			break;
	case PARAMETER:
			parameterCdma = buffer[0];
			break;
	case SDLC_PARM_OPTION:
		sdlcparmoptionCdma = buffer[0];
		break;
	case SDLC_PARM_ADDRESS: 
		sdlcparmaddressCdma = buffer[0];
		break;

	case PHONE_NUMBER:
			memset(phoneNoCdma, '\0', MAX_PHNO_LENGTH);
			memcpy(phoneNoCdma, buffer,size);
			return size;
	case INIT_STRING:
			memset(initStringCdma, '\0', MAX_INIT_STR_LEN);
			memcpy(initStringCdma, buffer,size);
			return size;
	case HANGUP_STRING:
			memset(hangUpStringCdma, '\0', MAX_HANGUP_STR_LEN);
			memcpy(hangUpStringCdma, buffer,size);
			return size;
	case STARTUP_STRING:
			memset(startUpStringCdma, '\0', MAX_STARTUP_STR_LEN);
			memcpy(startUpStringCdma, buffer,size);
			return size;
	case MODEL_NO:
			memset(modelNoCdma, '\0', MAX_MODEL_SIZE);
			memcpy(modelNoCdma, buffer,size);
			return size;
	case MIN_BATTERY_STRENGTH:
			minBatteryStrengthCdma = atoi((char*)buffer);		
			break;
	case MIN_SIGNAL_STRENGTH:
			minSignalStrengthCdma = atoi((char*)buffer);		
			break;
	case LOCAL_CMD_WAIT_TIME:
			lcWaitTimeCdma = atoi((char*)buffer);
			break;
	case NW_CMD_WAIT_TIME:
			nwWaitTimeCdma = atoi((char*)buffer);
			break;
	case APN:
			memset(apn, '\0', MAX_APN_LENGTH);
			memcpy(apn, buffer,size);
			return size;
	case PACKET_PROTOCOL:
			memset(packetProtocol, '\0',MAX_PACKET_PROTOCOL_SIZE);
			memcpy(packetProtocol, buffer,size);
			return size;

	default:

		return UCL_FAILURE;
	}
	return UCL_SUCCESS;
};
/****************************************************************************
* FUNCTION NAME		: NotifyCdma()

* INPUTS			: state    - ID of the parameter required
					 

* OUTPUTS			: return the terminal status

* DESCRIPTION		: This method is called by library APIs to inform the user about device status
                      and waits for the user response.  

****************************************************************************/

short NotifyCdma(short state)
{
	if(state == STATUS_RECV)
	{
		char buff[10]={0};
		retVal = act_kbd_pending_test(KEY_CANCEL);
		if(retVal == 1){
			state = -1;
			read(conHandle,buff,5);
		}
		else
			state = 0;
		
	}

	return state;

}


/****************************************************************************
* FUNCTION NAME		: GetParamGprs()

* INPUTS			: paramId - ID of the parameter required
					  value    - buffer to hold parameter value 
					  size     - size of the value. 

* OUTPUTS			: required ID value is updated and no. of bytes/errNo is returned 

* DESCRIPTION		: This method is called by library APIs to get the user specified values
                      of the communication parameters.  
 
****************************************************************************/

short GetParamCO(short paramId, unsigned char *buffer, short size)
{
	if((buffer == NULL) ||(size <= 0))
		return E_UCL_INVALID_PARM;
	
	memset(buffer,0,size);
	
	switch (paramId)
	{

	case BAUDRATE:
			buffer[0] = baudRateCO;
			buffer[1] = '\0';
			return SINGLE_CHAR_SIZE;
	
	case FORMAT:
			buffer[0] = formatCO;
			buffer[1] = '\0';
			return SINGLE_CHAR_SIZE;
	case PARAMETER:
			buffer[0] = parameterCO;
			buffer[1] = '\0';
			return SINGLE_CHAR_SIZE;
	case PROTOCOL:
			buffer[0] = protocolCO;
			buffer[1] = '\0';
			return SINGLE_CHAR_SIZE;

	case INIT_STRING:
			memcpy(buffer, initStringCO,MAX_INIT_STR_LEN);
			return MAX_INIT_STR_LEN;
	case HANGUP_STRING:
			memcpy(buffer, hangUpStringCO,MAX_HANGUP_STR_LEN);
			return MAX_HANGUP_STR_LEN;
	case STARTUP_STRING:
			memcpy(buffer, startUpStringCO,MAX_STARTUP_STR_LEN);
			return MAX_STARTUP_STR_LEN;
	case MODEL_NO:
			memcpy(buffer, modelNoCO,MAX_MODEL_SIZE);
			return MAX_MODEL_SIZE;
	default:
		break;
	}
	return UCL_FAILURE;
};


/****************************************************************************
* FUNCTION NAME		: SetParamCO()

* INPUTS			: paramId - ID of the parameter required
					  value    - buffer with parameter value 
					  size     - size of the value. 
  					 

* OUTPUTS			: returns if the internal data has been updated or not 
						SUCCESS /FAILURE

* DESCRIPTION		: This method is used by the application to update the 
						communication parameters.

****************************************************************************/

short SetParamCO(short paramId, unsigned char *buffer, short size)
{
	if(buffer == NULL)
		return UCL_FAILURE;
	if(size == 0)
		return UCL_FAILURE;
	switch (paramId)
	{
	case BAUDRATE:
			baudRateCO = buffer[0];
			break;
	case FORMAT:
			formatCO = buffer[0];
			break;

	case PROTOCOL:
			protocolCO = buffer[0];
			break;
	case PARAMETER:
			parameterCO = buffer[0];
			break;
	case INIT_STRING:
			memset(initStringCO, '\0', MAX_INIT_STR_LEN);
			memcpy(initStringCO, buffer,size);
			return size;
	case HANGUP_STRING:
			memset(hangUpStringCO, '\0', MAX_HANGUP_STR_LEN);
			memcpy(hangUpStringCO, buffer,size);
			return size;
	case STARTUP_STRING:
			memset(startUpStringCO, '\0', MAX_STARTUP_STR_LEN);
			memcpy(startUpStringCO, buffer,size);
			return size;
	case MODEL_NO:
			memset(modelNoCO, '\0', MAX_MODEL_SIZE);
			memcpy(modelNoCO, buffer,size);
			return size;
	default:

		return UCL_FAILURE;
	}
	return UCL_SUCCESS;
};
/****************************************************************************
* FUNCTION NAME		: NotifyCO()

* INPUTS			: state    - ID of the parameter required
					 

* OUTPUTS			: return the terminal status

* DESCRIPTION		: This method is called by library APIs to inform the user about device status
                      and waits for the user response.  

****************************************************************************/

short NotifyCO(short state)
{
	if(state == STATUS_RECV)
	{
		char buff[10]={0};
		retVal = act_kbd_pending_test(KEY_CANCEL);
		if(retVal == 1){
			state = -1;
			read(conHandle,buff,5);
		}
		else
			state = 0;
		
	}

	return state;

}

/****************************************************************************
* FUNCTION NAME		: GetParamGprs()

* INPUTS			: paramId - ID of the parameter required
					  value    - buffer to hold parameter value 
					  size     - size of the value. 

* OUTPUTS			: required ID value is updated and no. of bytes/errNo is returned 

* DESCRIPTION		: This method is called by library APIs to get the user specified values
                      of the communication parameters.  
 
****************************************************************************/

short GetParamWiFi(short paramId, unsigned char *buffer, short size)
{
	if((buffer == NULL) ||(size <= 0))
		return E_UCL_INVALID_PARM;
	
	memset(buffer,0,size);
	
	switch (paramId)
	{

	case BAUDRATE:
			buffer[0] = baudRateWiFi;
			buffer[1] = '\0';
			return SINGLE_CHAR_SIZE;
	
	case FORMAT:
			buffer[0] = formatWiFi;
			buffer[1] = '\0';
			return SINGLE_CHAR_SIZE;
	case PARAMETER:
			buffer[0] = parameterWiFi;
			buffer[1] = '\0';
			return SINGLE_CHAR_SIZE;
	case PROTOCOL:
			buffer[0] = protocolWiFi;
			buffer[1] = '\0';
			return SINGLE_CHAR_SIZE;
	case INIT_STRING:
			memcpy(buffer, initStringWiFi,MAX_INIT_STR_LEN);
			return MAX_INIT_STR_LEN;
	case HANGUP_STRING:
			memcpy(buffer, hangUpStringWiFi,MAX_HANGUP_STR_LEN);
			return MAX_HANGUP_STR_LEN;
	case STARTUP_STRING:
			memcpy(buffer, startUpStringWiFi,MAX_STARTUP_STR_LEN);
			return MAX_STARTUP_STR_LEN;
	case MODEL_NO:
			memcpy(buffer, modelNoWiFi,MAX_MODEL_SIZE);
			return MAX_MODEL_SIZE;
	case TERMINAL_TYPE :
			strcpy((char*)buffer,(char*)terminalTypeWiFi);
			return (strlen((char*)buffer));
	default:
		break;
	}
	return UCL_FAILURE;
};


/****************************************************************************
* FUNCTION NAME		: SetParamCO()

* INPUTS			: paramId - ID of the parameter required
					  value    - buffer with parameter value 
					  size     - size of the value. 
  					 

* OUTPUTS			: returns if the internal data has been updated or not 
						SUCCESS /FAILURE

* DESCRIPTION		: This method is used by the application to update the 
						communication parameters.

****************************************************************************/

short SetParamWiFi(short paramId, unsigned char *buffer, short size)
{
	if(buffer == NULL)
		return UCL_FAILURE;
	if(size == 0)
		return UCL_FAILURE;
	switch (paramId)
	{
	case BAUDRATE:
			baudRateWiFi = buffer[0];
			break;
	case FORMAT:
			formatWiFi = buffer[0];
			break;

	case PROTOCOL:
			protocolWiFi = buffer[0];
			break;
	case PARAMETER:
			parameterWiFi = buffer[0];
			break;
	case INIT_STRING:
			memset(initStringWiFi, '\0', MAX_INIT_STR_LEN);
			memcpy(initStringWiFi, buffer,size);
			return size;
	case HANGUP_STRING:
			memset(hangUpStringWiFi, '\0', MAX_HANGUP_STR_LEN);
			memcpy(hangUpStringWiFi, buffer,size);
			return size;
	case STARTUP_STRING:
			memset(startUpStringWiFi, '\0', MAX_STARTUP_STR_LEN);
			memcpy(startUpStringWiFi, buffer,size);
			return size;
	case MODEL_NO:
			memset(modelNoWiFi, '\0', MAX_MODEL_SIZE);
			memcpy(modelNoWiFi, buffer,size);
			return size;
	default:

		return UCL_FAILURE;
	}
	return UCL_SUCCESS;
};
/****************************************************************************
* FUNCTION NAME		: NotifyCO()

* INPUTS			: state    - ID of the parameter required
					 

* OUTPUTS			: return the terminal status

* DESCRIPTION		: This method is called by library APIs to inform the user about device status
                      and waits for the user response.  

****************************************************************************/

short NotifyWiFi(short state)
{
	return(state);
	if(state == STATUS_RECV)
	{
		char buff[10]={0};
		retVal = act_kbd_pending_test(KEY_CANCEL);
		if(retVal == 1){
			state = -1;
			read(conHandle,buff,5);
		}
		else
			state = 0;
	}
}



AppObj appObj;

AppObj *CreateAppObj(short type)
{
	switch (type)
	{
	case 0:
		appObj.super.GetParam = GetParamLandLine;
		appObj.super.Notify = NotifyLandLine;
		appObj.SetParam = SetParamLandLine;
		break;
	case 1:
		appObj.super.GetParam = GetParamGsm;
		appObj.super.Notify = NotifyGsm;
		appObj.SetParam = SetParamGsm;
		break;
	case 2:
		appObj.super.GetParam = GetParamGprs;
		appObj.super.Notify = NotifyGprs;
		appObj.SetParam = SetParamGprs;
		break;
	case 3:
		appObj.super.GetParam = GetParamCdma;
		appObj.super.Notify = NotifyCdma;
		appObj.SetParam = SetParamCdma;
		break;
	case 4:
		appObj.super.GetParam = GetParamCO;
		appObj.super.Notify = NotifyCO;
		appObj.SetParam = SetParamCO;
		break;
	case 5:
		appObj.super.GetParam = GetParamWiFi;
		appObj.super.Notify = NotifyWiFi;
		appObj.SetParam = SetParamWiFi;
		break;
	default:
		return NULL;
	}
	return  &appObj;
};
